package com.shengyijie.model.database.dataoperate;
 
 
 

import com.shengyijie.model.database.DBHandler;
import com.shengyijie.model.object.baseobject.User; 

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/** @title: CouponDB 
 * @description: CouponDB
 * @copyright: Diipo (c) 2011.6 
 * @company: Diipo 
 * @author liukun 
 * @version 1.0 
 */ 
public class AccountInfoDB extends DBHandler{

	public static String TABLE_ACCOUNT="accountinfo";
	public static String COLUMN_ID="id";
	public static String COLUMN_Type="type";
	public static String COLUMN_SESSIONID="sessionid";
	public static String COLUMN_IS_REMEMBER="remember";
	public static String COLUMN_NAME="name";
	public static String COLUMN_PASSWORD="passwords";  
	public static String COLUMN_EMAIL="emails";
	public static String COLUMN_MOBILE="mobile";
	public static String COLUMN_COME_TYPE="comtype";
	public static String COLUMN_REG_STATUS="reg_status"; 
	public AccountInfoDB(Context ctx, String base_name, int version) {
		super(ctx, base_name, version);
	}

	public void createTable(){
		if(!isTableExits(TABLE_ACCOUNT)){
		   String sql = "create table "+AccountInfoDB.TABLE_ACCOUNT+" (id text,type INTEGER,sessionid text,remember INTEGER);";              
           db.execSQL(sql);
		}
	}
	public void deleteTable(){
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_ACCOUNT);
	}
	public long insertItem(String id,int type,String sessionid,int isRem) {
		deleteAllRecords();
		ContentValues initialValues = new ContentValues();
		initialValues.put(COLUMN_ID,id); 
		initialValues.put(COLUMN_Type,type);
		initialValues.put(COLUMN_SESSIONID,sessionid);
		initialValues.put(COLUMN_IS_REMEMBER,isRem);
		//initialValues.put(COLUMN_PASSWORD,password);
//		initialValues.put(COLUMN_DES,des);
//		initialValues.put(COLUMN_LOGO_URL,logo);
//		initialValues.put(COLUMN_CREATE_AT,create);
//		initialValues.put(COLUMN_EMAIL,email);
//		initialValues.put(COLUMN_TIME_ZONE,time_zone);
//		initialValues.put(COLUMN_LAT,lat); 
//		initialValues.put(COLUMN_LNG,lng); 
//		initialValues.put(COLUMN_FULL_NAME,fname); 
		return db.insert(TABLE_ACCOUNT,null,initialValues);
	}
	
	public long insertItem(User user) {	 
		if(isTableExits(TABLE_ACCOUNT)&&user!=null){ 
			return insertItem(user.getUserID(),user.getUserType(),user.getSession_ID(),user.getIsRemember());
		}
		    
		return -1;
	}
 

	public Cursor  fetchAllRecords(){
		if(isTableExits(TABLE_ACCOUNT))
		   return db.query(TABLE_ACCOUNT, new String[]{COLUMN_ID,COLUMN_Type,COLUMN_SESSIONID,COLUMN_IS_REMEMBER}, 
		            null, null, null, null, null);
		return null;
    }

	public boolean deleteAllRecords() { 
		if(isTableExits(TABLE_ACCOUNT))
	        return db.delete(TABLE_ACCOUNT, null, null) > 0;
	     return false;

	}
	 

	 
	 
	
	public SQLiteDatabase getDB(){
		return this.db;
	}
}


